﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BookManage
{
    public partial class Admin22 : Form
    {
        public Admin22()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            if(textBox1.Text!=""&& textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "")
            {
                string id = textBox1.Text;
                string name = textBox2.Text;
                string author = textBox3.Text;
                string press = textBox4.Text;
                int number = int.Parse(textBox5.Text);
                string sql = $"insert into t_book  values('{id}','{name}','{author}','{press}',{number});";

                Dao dao = new Dao();
                int n = dao.Execute(sql);//n表示sql语句影响的行数

                if (n > 0)
                {
               
                    MessageBox.Show("添加成功");
                    textBox1.Text = "";
                    textBox2.Text = "";
                    textBox3.Text = "";
                    textBox4.Text = "";
                    textBox5.Text = "";
                    
                }
                else
                {
                    MessageBox.Show("添加失败");
                }


                dao.DaoClose();
            }
            else
            {
                MessageBox.Show("输入不允许有空项");
            }
            
        }
    }
}
